﻿using System;
using System.Web;
using System.Web.Script.Serialization;
using Easy.Operation;

namespace Easy.Web.Service.Privilege
{
    /// <summary>
    /// UserRoleSetting 的摘要说明
    /// </summary>
    public class UserRoleSetting : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            string json = context.Request["json"];
           
            string optionUser = context.Request["optionUser"];

            ResultClass rc = new ResultClass();

            try
            {

                JavaScriptSerializer jss = new JavaScriptSerializer();

                UserRoleClass ur = jss.Deserialize<UserRoleClass>(json);

                if (ur.UserId == "" || ur.UserId.Length != 36)
                {
                    rc.Result = 1;
                    rc.Remark = "请提供要修改的用户ID";
                }
                else
                {
                    
                    string savedid = UserPrivilege_Functions.UserRole_Save(ur, optionUser);

                    rc.Result = 0;
                    rc.Remark = savedid;
                }
            }
            catch (Exception e)
            {
                rc.Result = 1;
                rc.Remark = e.Message;
            }


            context.Response.Write(rc.ToJson());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}